<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="挂号单ID" prop="regID">
        <el-input
          v-model="queryParams.regID"
          placeholder="请输入挂号单"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">读取IC卡</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="chargeList" @selection-change="handleSelectionChange">

      <el-table-column label="挂号单号" align="center" prop="regID"/>
      <el-table-column label="科室名称" align="center" prop="regDepts"/>
      <el-table-column label="就诊时间" align="center" prop="regSdate"/>
      <el-table-column label="诊断信息" align="center" prop="charMedCase.caseDaigInfo"/>
      <el-table-column label="医生姓名" align="center" prop="regDocter"/>
      <el-table-column label="患者姓名" align="center" prop="patiName"/>
      <el-table-column label="主诉" align="center" prop="charMedCase.caseComplaint"/>
      <el-table-column label="医生建议" align="center" prop="charMedCase.caseAdvise"/>
      <!--   <template slot-scope="scope">
           <span>{{ parseTime(scope.row.regSdate ,'{y}-{m}-{d}') }}</span>
         </template>-->
    </el-table>


    <el-collapse v-model="activeNames" @change="handleChange">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['drugs:supplier:add']"
          >全选
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="multiple"
            @click="handleUpdate"
            v-hasPermi="['drugs:supplier:edit']"
          >取消全选
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['drugs:supplier:remove']"
          >支付
          </el-button>
        </el-col>

      </el-row>
      <el-collapse-item title="【检查处方】【1】【处方总额】:¥105" name="1">
        <div>

        </div>
      </el-collapse-item>
      <el-collapse-item title="【药品处方】【2】【处方总额】:¥16" name="2">
        <div>
          <el-table v-loading="loading" :data="chargeList" @selection-change="handleSelectionChange">

              <el-table-column type="selection" width="55" align="center"/>
              <el-table-column  label="序号" align="center" prop="list[0].medicalId"/>
              <el-table-column label="药品ID" align="center" prop="list[0].medicalId"/>
              <el-table-column label="数量" align="center" prop="list[0].medicalNum"/>
              <el-table-column label="金额（元）" align="center" prop="list[0].medicalPrice"/>
              <el-table-column label="服用备注" align="center" prop="list[0].medicalRemark"/>
              <el-table-column label="支付状态" align="center" prop="list[0].payStatus" :formatter="statusFormat"/>
          </el-table>
        </div>


      </el-collapse-item>
    </el-collapse>



  </div>
</template>

<script>
  //import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post";
  import {listSup} from "@/api/charge/pcharge";


  export default {

    name: "charge",
    data() {
      return {
        // 遮罩层
        loading: false,
        activeNames: ['1'],
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        chargeList: [],
        medicalList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态数据字典
        statusOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          regID: undefined,

        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          name: [
            {required: true, message: "供应商名称不能为空", trigger: "blur"}
          ],
          boss: [
            {required: true, message: "联系人不能为空", trigger: "blur"}
          ],
          phone: [
            {required: true, message: "手机号不能为空", trigger: "blur"}
          ],
          card: [
            {required: true, message: "银行卡号不能为空", trigger: "blur"}
          ],
          address: [
            {required: true, message: "地址不能为空", trigger: "blur"}
          ]
        }
      };
    },
    created() {
      this.getDicts("sys_charge_status").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      /** 查询供应商列表 */
      getList() {
        this.loading = true;
        listSup(this.queryParams).then(response => {
          this.chargeList = response.rows;
          this.medicalList = response.rows.list;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 供应商状态字典翻译
      statusFormat(row, column) {
        return this.selectDictLabel(this.statusOptions, row.list[0].payStatus);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          name: undefined,
          boss: undefined,
          phone: undefined,
          card: undefined,
          address: undefined,
          postSort: 0,
          status: "0",
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },

      handleChange(val) {
        console.log(val);
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();

      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getSup(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改供应商";
        });
      },
      /** 提交按钮 */
      submitForm: function () {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != undefined) {
              updateSup(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addSup(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const id = row.id || this.ids;
        this.$confirm('是否确认删除岗位编号为"' + id + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delSup(id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
    }
  };
</script>
